Set a view?

Hi,

I have a problem with the statement "setDefaultViewForModule". My code goes like this:

 

Item i
        
        for i in f do
        {
            currentModule = read(fullName(i), false, true)

            //Debug
            print "Current Module: " name(currentModule) "\n"
            
            //Sets the used view to "IntegrTest_Export"
            string v
            for v in views(currentModule) do
            {
                if(v == get(mainView))
                {
                    //Debug
                    print "mainView was found! \n"
                    string myMainView = get(mainView)
                    setDefaultViewForModule(currentModule, myMainView)
                    
                    //Debug
                    print "mainView: " myMainView "\n"
                    
                    break    //If the view is found which is assigned from user through GUI input break and exit "search"-for-loop
                }
                else
                {
                    //Debug
                    print "mainView was not found! \n"
                    setDefaultViewForModule(currentModule, getDefaultViewForModule(currentModule))
                }
            }

    .....

 

In the first iteration of the first for-loop the view assigning with  setDefaultViewForModule(currentModule, myMainView) goes perfectly. But if the 2nd iteration of the first for-loop starts, the code obviously don't assign right. With the 2nd for-loop I search in the current Module if the needed view is available; if not, theDefaultview should be used (else-path of the if-statement in the 2n for-loop).

 

Can anyone say me, why the 2nd iteration (next module in folder) don't assign the default view depending on myMainView?

 

Edit: I have now seen, that the right view is always used, if the Module is opened. But, I have programmed a Excel-export which exports all Modules in a doors folder to one excel workbook and every module in another excel worksheet. My question now is: What I have to do, that the statement "setDefaultViewForModule" is used if the current module from the folder is NOT opened? Are you understand what I mean?


tobi_mehrl - Mon Jun 29 05:31:39 EDT 2015

Re: Set a view?
woodpryan - Mon Jun 29 12:20:33 EDT 2015

You may find the following function I wrote useful:

/*  Function:   loadViewInvisible(string, &Module)
    Purpose:    Loads the specified view without visibly opening the specified Module
                if the view and Module exist. The function is necessary because DXL
                does not provide a way of opening a view without doing so visibly.
                This function changes the default view for the user, loads the Module,
                and then changes the default view back.
                If the view name passed to the function is Standard view, there needs to
                not be any handles to this Module because this function cannot invisibly load
                the standard view.
    Parameters: the View name, a reference to the Module
    Return:     success
*/
bool loadViewInvisible(string vName, Module &mod)
{
    string   defViewName = null;
    string   err         = null;
    string   modName     = null;
    
    modName = fullName(mod);
    defViewName = getDefaultViewForUser(mod);
    err = setDefaultViewForUser(mod, vName);
    if(null != err)
    {
        logError("Could not set new default view: " vName " for Module: " modName);
        logMessage("setDefualtViewForUser returned the following error: \n" err);
        return false;
    }
    if(null == modName)
    {
        logError("Could not retrieve the Module Name from the Module passed to loadViewInvisible");
        return false;
    }
    
    mod = read(modName, false);
    if(null == defViewName)
            clearDefaultViewForUser(mod)
    else
        err = setDefaultViewForUser(mod, defViewName);
        
    if(null != err)
    {
        logError("Changed default view for user on Module " modName " and failed to change it back.");
        logMessage("setDefaultViewForUser returned the following error: \n" err);
    }
    
    logMessage("Loaded view " currentView(mod) " for Module " modName);
        
    return true;
}


 

Re: Set a view?
llandale - Mon Jul 06 17:21:08 EDT 2015

woodpryan forget to mention that dealing with views on an invisible module is "problematic".  "Problematic" means I don't remember all the pit-falls.

Open the module visibly.  If that doesn't solve your problems:

Your loop is flawed.  I assume "get(mainView)" is getting the main view NAME off the dialog.

  1. move above the view loop this line:
     string myMainView = get(mainView)
  2. declare this above the view loop:
    bool Found = false
  3. do this above your "break":
    Found = true
  4. Move your "else" clause below the view loop
  5. Change the "else" to:
    if (!Found)
  6. You don't need to set the default view to the current default view.  I wonder what happens if there is no such default view.

-Louie

ps: add this before the "read" command:
if (type(I) != "Formal") then continue

Re: Set a view?
llandale - Mon Jul 06 17:41:48 EDT 2015

woodpryan - Mon Jun 29 12:20:33 EDT 2015

You may find the following function I wrote useful:

/*  Function:   loadViewInvisible(string, &Module)
    Purpose:    Loads the specified view without visibly opening the specified Module
                if the view and Module exist. The function is necessary because DXL
                does not provide a way of opening a view without doing so visibly.
                This function changes the default view for the user, loads the Module,
                and then changes the default view back.
                If the view name passed to the function is Standard view, there needs to
                not be any handles to this Module because this function cannot invisibly load
                the standard view.
    Parameters: the View name, a reference to the Module
    Return:     success
*/
bool loadViewInvisible(string vName, Module &mod)
{
    string   defViewName = null;
    string   err         = null;
    string   modName     = null;
    
    modName = fullName(mod);
    defViewName = getDefaultViewForUser(mod);
    err = setDefaultViewForUser(mod, vName);
    if(null != err)
    {
        logError("Could not set new default view: " vName " for Module: " modName);
        logMessage("setDefualtViewForUser returned the following error: \n" err);
        return false;
    }
    if(null == modName)
    {
        logError("Could not retrieve the Module Name from the Module passed to loadViewInvisible");
        return false;
    }
    
    mod = read(modName, false);
    if(null == defViewName)
            clearDefaultViewForUser(mod)
    else
        err = setDefaultViewForUser(mod, defViewName);
        
    if(null != err)
    {
        logError("Changed default view for user on Module " modName " and failed to change it back.");
        logMessage("setDefaultViewForUser returned the following error: \n" err);
    }
    
    logMessage("Loaded view " currentView(mod) " for Module " modName);
        
    return true;
}


 

The basic rules:

  1. If the module is visible, a "read" command will not load the default view but the view "load" command will load the view.
  2. If the module is invisible, a "read" command will indeed load the default view but the view "load" command won't load the view.

So, like you are doing, if the module is invisible you swap the default view for the specified one; "read" the module again; then swap it back.
If the module is visible then forgo any "read"s and go ahead and "load" the view.  Unless they want the Standard view in which case you issue the "read" command with that option off.

I used the default view for the user; not the module.

My far more verbose and complicated function is in here:

https://www.ibm.com/developerworks/community/forums/html/topic?id=77777777-0000-0000-0000-000014775427&ps=25

-Louie

Seems to me I ran into an anomaly where you could not "swap back", but I don't recall what that was.

Re: Set a view?
woodpryan - Mon Jul 06 17:48:35 EDT 2015

llandale - Mon Jul 06 17:41:48 EDT 2015

The basic rules:

  1. If the module is visible, a "read" command will not load the default view but the view "load" command will load the view.
  2. If the module is invisible, a "read" command will indeed load the default view but the view "load" command won't load the view.

So, like you are doing, if the module is invisible you swap the default view for the specified one; "read" the module again; then swap it back.
If the module is visible then forgo any "read"s and go ahead and "load" the view.  Unless they want the Standard view in which case you issue the "read" command with that option off.

I used the default view for the user; not the module.

My far more verbose and complicated function is in here:

https://www.ibm.com/developerworks/community/forums/html/topic?id=77777777-0000-0000-0000-000014775427&ps=25

-Louie

Seems to me I ran into an anomaly where you could not "swap back", but I don't recall what that was.

I don't believe I've had any difficulty with the function I wrote. The calling program does a bunch of testing for 'Standard' View and whether the Module is visible and whatnot. It takes care of that stuff, so this function was kept fairly simple. Your way of commenting your functions is quite impressive.

Re: Set a view?
Wolfgang Uhr - Tue Jul 07 05:10:12 EDT 2015

woodpryan - Mon Jul 06 17:48:35 EDT 2015

I don't believe I've had any difficulty with the function I wrote. The calling program does a bunch of testing for 'Standard' View and whether the Module is visible and whatnot. It takes care of that stuff, so this function was kept fairly simple. Your way of commenting your functions is quite impressive.

> I don't believe I've had any difficulty with the function I wrote.

I'm shure that there is no problem. The problem is: Why do you load a view, which you cannot see. If a module is intended to be loaded invisible, you load the standard view and write a view independend code. The script you have shown is more another problem than a solution.

 

> Your way of commenting your functions is quite impressive.

You know, that the most of us are sitting behind a firewall and so the most of this java script gimicks of the forum did not work? This is a !*@*!"-Forum

Re: Set a view?
llandale - Tue Jul 07 10:51:13 EDT 2015

woodpryan - Mon Jul 06 17:48:35 EDT 2015

I don't believe I've had any difficulty with the function I wrote. The calling program does a bunch of testing for 'Standard' View and whether the Module is visible and whatnot. It takes care of that stuff, so this function was kept fairly simple. Your way of commenting your functions is quite impressive.

I have a very strong favor for library functions.  Just about every technique I post is in the form of a function.

I didn't suggest your function was wrong.  It requires the caller to check for the visibility of the module and deal with the Visible case as well.  I suggest that it is "better" to relieve the calling program from as much detail as possible; in this case the function "should" load the view and deal with the visibility aspects itself.  A "novice" trying to use your function won't know exactly how to use it.

-Louie

"Impressive" having the meaning "Verbose".  It is indeed a character flaw but I routinely have far too many "too much information" errors than "not enough information" errors; in all sorts of ways such as emails.  And posts.

Re: Set a view?
woodpryan - Tue Jul 07 11:32:01 EDT 2015

Wolfgang Uhr - Tue Jul 07 05:10:12 EDT 2015

> I don't believe I've had any difficulty with the function I wrote.

I'm shure that there is no problem. The problem is: Why do you load a view, which you cannot see. If a module is intended to be loaded invisible, you load the standard view and write a view independend code. The script you have shown is more another problem than a solution.

 

> Your way of commenting your functions is quite impressive.

You know, that the most of us are sitting behind a firewall and so the most of this java script gimicks of the forum did not work? This is a !*@*!"-Forum

Actually, there was a very good reason the Views needed to be loaded invisibly.

Re: Set a view?
llandale - Tue Jul 07 14:08:29 EDT 2015

woodpryan - Tue Jul 07 11:32:01 EDT 2015

Actually, there was a very good reason the Views needed to be loaded invisibly.

Sure.  It runs drastically faster than loading modules visibly.

Having said that I get the willy-nilly's having DXL dependent on the characteristics of a view.  If you change the Filter the script gets different results which is a relative disaster for any script that makes a report.  Be sure you got good control over your views; including the ability to push a view out from a template module.

-Louie

Re: Set a view?
woodpryan - Tue Jul 07 15:10:39 EDT 2015

llandale - Tue Jul 07 14:08:29 EDT 2015

Sure.  It runs drastically faster than loading modules visibly.

Having said that I get the willy-nilly's having DXL dependent on the characteristics of a view.  If you change the Filter the script gets different results which is a relative disaster for any script that makes a report.  Be sure you got good control over your views; including the ability to push a view out from a template module.

-Louie

Bingo. Exactly what was happening with that function. Called by a script that exports a bunch of stuff into an MS Word document. And the calling function also did different things depending on the View it needed to export was in a Module opened visibly vs not open at all/invisibly, etc. Not only does the View load more quickly invisible, but less RAM is used, which is important when exporting a massive amount of data from DOORS.